package com.loan.system.domain.work.domain;

import com.loan.common.pdf.PDFUtil;
import com.loan.common.utils.StringUtils;
import com.loan.system.create.domain.AssistPdfSearchNhBase;
import lombok.Data;

import java.math.BigDecimal;

/**
 * packageName com.loan.web.pdf.domain
 *
 * @author Sophia
 * @className NhPdfDomain
 * @description TODO NH文件生成的字段信息
 * @date 2024/11/4
 */
@Data
public class NhPdfDomain {

    /**
     * 交易日期
     */
    private String transactionDate;

    /**
     * 交易时间
     */
    private String transactionTime;
    /**
     * 交易摘要
     */
    private String transactionSummary;

    /**
     * 交易金额
     */
    private String transactionAmount;

    /**
     * 本次余额
     */
    private String currentBalance;

    /**
     * 交易类型
     */
    private String transactionType;

    /**
     * 对手信息
     */
    private String oppositionInformation;

    /**
     * 日志号
     */
    private String logNo;

    /**
     * 交易渠道
     */
    private String transactionChannels;

    /**
     * 交易附言
     */
    private String transactionNote;

    /**
     * 序号
     */
    private Integer sortNo;

    // Integet类型交易金额
    private Integer transactionMoneyInt;
    // 金额小数点后数字
    private String afterNum;


    public NhPdfDomain() {
    }

    public NhPdfDomain(AssistPdfSearchNhBase base, BigDecimal currentBalance, Integer sortNo) {
        this.transactionSummary = base.getNhBaseTransactionSummary();
        this.transactionAmount = base.getNhBaseTransactionType() + String.valueOf(base.getNhBaseTransactionAmount());
        this.transactionMoneyInt = base.getNhBaseTransactionAmount().intValue();
        this.currentBalance = String.valueOf(currentBalance);
        this.oppositionInformation = base.getNhBaseOppositionInformation();
        if (StringUtils.isNotBlank(base.getNhBaseLogNo())) {
            this.logNo = base.getNhBaseLogNo();
        } else {
            if (StringUtils.equalsAny(base.getNhBaseTransactionSummary(), "结息", "利息税")) {
                this.logNo = "1";
            } else {
                this.logNo = PDFUtil.getRandomValue();
            }
        }
        this.transactionChannels = base.getNhBaseTransactionChannels();
        this.transactionNote = base.getNhBaseTransactionNote();
        this.sortNo = sortNo;
        this.afterNum = (this.transactionAmount.contains(".") && this.transactionAmount.length() > 3) ? this.transactionAmount.substring(this.transactionAmount.length() - 3) : ".00";
    }

    /**
     * 获取修改并重组后的金额值
     * @return
     */
    public String getDealAmount() {
        return String.format("%s%s%s", this.getTransactionType(), this.getTransactionMoneyInt(), this.getAfterNum());
    }
}
